from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel
from typing import Optional
from module_admin.annotation.pydantic_annotation import as_query, as_form


class RuleModel(BaseModel):
    """
    在线用户对应pydantic模型
    """

    model_config = ConfigDict(alias_generator=to_camel, from_attributes=True)

    rule_id: Optional[int] = Field(default=None, description='规则id')
    schema_name: Optional[str] = Field(default=None, description='模式')
    table_name: Optional[str] = Field(default=None, description='表名')
    sql_name: Optional[str] = Field(default=None, description='脚本名')
    check_type: Optional[str] = Field(default=None, description='校验类型')
    check_grade: Optional[str] = Field(default=None, description='校验级别')
    cal_rule: Optional[str] = Field(default=None, description='计算规则')
    field_name: Optional[str] = Field(default=None, description='字段名')
    compare_value: Optional[int] = Field(default=None, description='比较值')
    filter_condition: Optional[str] = Field(default=None, description='过滤条件')
    check_cycle: Optional[str] = Field(default=None, description='校验周期')
    status: Optional[str] = Field(default=None, description='是否启用')
    sql_template: Optional[str] = Field(default=None, description='sql模版')
    execute_sql: Optional[str] = Field(default=None, description='执行sql')
    work_date: Optional[datetime] = Field(default=None, description='作业日期')
    cp_date: Optional[datetime] = Field(default=None, description='对照组日期')
    create_by: Optional[str] = Field(default=None, description='创建者')
    create_time: Optional[datetime] = Field(default=None, description='创建时间')
    update_by: Optional[str] = Field(default=None, description='更新者')
    update_time: Optional[datetime] = Field(default=None, description='更新时间')


class RuleQueryModel(RuleModel):


    begin_time: Optional[str] = Field(default=None, description='开始时间')
    end_time: Optional[str] = Field(default=None, description='结束时间')

@as_query
@as_form
class RulePageQueryModel(RuleQueryModel):
    """
    字典类型管理分页查询模型
    """

    page_num: int = Field(default=1, description='当前页码')
    page_size: int = Field(default=10, description='每页记录数')

class DeleteRuleModel(BaseModel):
    """
    强退在线用户模型
    """

    model_config = ConfigDict(alias_generator=to_camel)

    token_ids: str = Field(description='需要强退的会话编号')
